/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package praticas.projeto.persistencia;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Map;

/**
 *
 * @author lucasmarques
 */
public class Persistencia {

    private File file;

    public Persistencia(String fileName) {
        file = new File(fileName);
    }


    /*
     * Grava em um arquivo.txt um objeto do tipo MAP!
     */
    public void gravaArquivo(Map usuario) throws IOException{
        ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(file));
        try{
        out.writeObject(usuario);
        }finally{
        out.close();
        }

    }

    /*
     * Ler um arquivo.txt um objeto do tipo MAP!
     */
    public Map lerArquivo() throws IOException, ClassNotFoundException{
        Map usuario;
        ObjectInputStream in = new ObjectInputStream( new FileInputStream(file));
        try{
        usuario = (Map) in.readObject();
        }finally{
         in.close();
        }
         return usuario;
    }   



}
